home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-03 / qbasicpg.zip / QCARDS.BAS (.txt) < prev    next >
QuickBASIC Tokenized Source  |  1988-09-23  |  35KB  |  563 lines

  1. SPACE
  2. ENTER
  3. TABKEY
  4. RIGHT
  5. PGDNV
  6. NULL'
  7. CTRLD
  8. CTRLG
  9. CTRLHL
  10. CTRLSx
  11. CTRLV$
  12. BLACK9
  13. BLUEH
  14. GREEN]
  15. CYAN7
  16. MAGENTA-
  17. YELLOW
  18. WHITEn
  19. BRIGHT
  20. BACKGROUND
  21. NORMALp
  22. HILITE
  23. CNORMAL
  24. CHILITE
  25. HELPTOP
  26. HELPBOT>
  27. HELPLEFTR
  28. HELPWID
  29. CARDSPERSCREENe
  30. LASTROW
  31. FALSE
  32. TRUEf
  33. CURSORON
  34.     CURSOROFF
  35. TMPFILE
  36. DISKFILE
  37. NPERSON?
  38. NNOTE&
  39. NMONTH
  40. NDAYJ
  41. NYEARx
  42. NPHONE
  43. NSTREET
  44. NCITY
  45. NSTATE
  46. NFIELDS
  47. PERSON
  48. CardNum
  49. Names
  50. NoteE
  51. Month
  52. Phone
  53. Street4
  54. CityL
  55. State
  56. Alarm
  57. DirectionKeyx
  58. Choice2
  59. TopCard
  60. LastCard
  61. AsciiKey=
  62. CleanUpk
  63. @    ClearHelpW
  64. @    DrawCards
  65. EditCard
  66. @    InitIndex
  67. PrintLabel
  68. @    SortIndex
  69.     SortField
  70. ShowViewHelpr
  71. ShowTopCard
  72. WorkCard(
  73. ShowEditHelp
  74. ShowCmdLine
  75. @    ShowCards
  76. EditString
  77. InString)
  78. Length{
  79.     NextField
  80. FindCard
  81. Prompt
  82. Column(
  83. SelectField
  84.     MemoryErr
  85. Index
  86. Card.CardNum\
  87. CardScreen
  88. ViewHelp
  89. EditHelpX
  90. FieldPositions
  91. UserChoice
  92. WorkCard.CardNum
  93. WorkCard.NamesJ
  94. WorkCard.Note
  95. WorkCard.Montho
  96. WorkCard.Day
  97. WorkCard.Year
  98. WorkCard.Phone
  99. WorkCard.Street
  100. WorkCard.City`
  101. WorkCard.State
  102. WorkCard.Zip3
  103. NextFlag*
  104. Card.Names
  105.     Card.NoteF
  106. Card.Month
  107. Card.DayS
  108.     Card.Year
  109. Card.Phone
  110. Card.Street
  111.     Card.City
  112. Card.State
  113. Card.Zip>
  114. Insert
  115. Workw
  116.     FirstTime
  117. TmpCard
  118. NotFirst
  119. TmpCard.Names
  120. TmpCard.Note
  121. TmpCard.Phone
  122. TmpCard.Street
  123. TmpCard.City
  124. TmpCard.State=
  125. TmpCard.Zip
  126. Found
  127. Record
  128. FieldNumr
  129. Count 
  130. Offset
  131. Limit
  132. Switch
  133. drawcard`
  134.  Define English names for color-specification numbers. Add BRIGHT to
  135. * QCards - A simple database using a cardfile user interface.
  136. * Each record in the database is represented by a card. The user
  137. * can scroll through the cards using normal scrolling keys. 
  138. * Other commands allow the user to edit, add, sort, find, or
  139. * delete cards.s
  140. * Input:  Keyboard - user commands and entries
  141.      File - database recordso
  142. * Output: Screen - card display and help
  143.      File - database recordsp
  144.  The module-level code begins here. 
  145. * Declarations and definitions begin here 
  146. Resets the default data type from single precision to integer
  147.  Define names similar to keyboard names with their equivalent key codes.
  148.  Define English names for color-specification numbers. Add BRIGHT to
  149.  any color to get bright version.p
  150.  Assign colors to different kinds of text. By changing the color assigned,
  151.  you can change the color of the QCARDS display. The initial colors aree
  152.  chosen because they work for color or black-and-white displays.
  153.  Codes for normal and highlight (used in data statements)s
  154.  Screen positions - Initialized for 25 rows. Screen positions can be
  155.  modified for 43-row mode if you have an EGA or VGA adapter.
  156.  Miscellaneous symbolic constantsh
  157.  File names
  158. $$$87y$.$5$"
  159.  Unlikely file nameE
  160.  Field names
  161.  Declare user-defined type (a data structure) for random-access file records.
  162. First element is card number
  163. Names (in order for alphabetical sort)
  164. Note about persono
  165. Birth montht
  166. Birth dayt
  167. Birth year
  168. Phone number
  169. Street address
  170. State
  171. Zip code
  172.  SUB procedure declarations begin here.e
  173.  This space reserved e
  174.  FUNCTION procedure declarations begin here.
  175.  Procedure declarations end here.b
  176.  Define temporary Index() array to illustrate QCARDS screen.
  177.  Define a dummy record as a work card.
  178. * Declarations and definitions end here 
  179.  The execution-sequence logic of QCARDS begins here.
  180.  Open data file QCARDS.DAT for random access using file #1
  181.  To count records in file, divide the length of the file by the 
  182.  length of a single record; use integer division (\) instead of 
  183.  normal division (/). Assign the resulting value to LastCard.o
  184.  Redefine the Index array to hold the records in the file plus
  185.  20 extra (the extra records allow the user to add cards).
  186.  This array is dynamic - this means the number of elements
  187.  in Index() varies depending on the size of the file.m
  188.  Also, Index() is a shared procedure, so it is available to
  189.  all SUB and FUNCTION procedures in the program.
  190.  Note that an error trap lets QCARDS terminate with an error
  191.  message if the memory available is not sufficient. If nor
  192.  error is detected, the error trap is turned off following the
  193.  REDIM statement.d
  194.  Use the block IF...THEN...ELSE statement to decide whethert
  195.  to load the records from the disk file QCARDS.DAT into thet
  196.  array of records called Index() declared earlier. In the IF
  197.  part, you will check to see if there are actually records
  198.  in the file. If there are, LastCard will be greater than 0,
  199.  and you can call the InitIndex procedure to load the records
  200.  into Index(). LastCard is 0 if there are no records in thed
  201.  file yet. If there are no records in the file, the ELSE
  202.  clause is executed. The code between ELSE and END IF starts
  203.  the Index() array at card 1. 
  204.  Use the DrawCards procedure to initialize the screen 
  205.  and draw the cards. Then, set the first card as the top
  206.  card. Finally, pass the variables TopCard and LastCardp
  207.  as arguments to the ShowCards procedure. The call tor
  208.  ShowCards places all the data for TopCard on the front
  209.  card on the screen, then it places the top-line
  210.  information (the person's name) on the remaining cards.
  211.  Keep the picture on the screen forever with an unconditional
  212.  DO...LOOP statement. The DO part of the statement goes on
  213.  the next code line. The LOOP part goes just before the END
  214.  statement. This loop encloses the central logic that lets
  215.  a user interact with QCARDS.s
  216.  Get user keystroke with a conditional DO...LOOP statement.
  217.  Within the loop, use the INKEY$ function to capture a user
  218.  keystroke, which is then assigned to a string variable. The
  219.  WHILE part of the LOOP line keeps testing the stringl
  220.  variable. Until a key is pressed, INKEY$ keeps returning ae
  221.  null (that is a zero-length) string, represented by "".
  222.  When a key is pressed, INKEY$ returns a string with a
  223.  length greater than zero, and the loop terminates.h
  224.  Use the LEN function to find out whether Choice$ is greater
  225.  than a single character (i.e. a single byte). If Choice$ is
  226.  a single character (that is, it is less than 2 bytes long),
  227.  the key pressed was an ordinary "typewriter keyboard"
  228.  character (these are usually called ASCII keys because they
  229.  are part of the ASCII character set). When the user entersy
  230.  an ASCII character, it indicates a choice of one of the QCARDS
  231.  commands from the command line at the bottom of the screen.
  232.  If the user did press an ASCII key, use the LCASE$ function
  233.  to convert it to lower case (in the event the capital letter
  234.  was entered).
  235.  The ELSE clause is only executed if Choice$ is longer than a
  236.  single character (and therefore not a command-line key).a
  237.  If Choice$ is not an ASCII key, it represents an "extended"
  238.  key. (The extended keys include the DIRECTION keys on the
  239.  numeric keypad, which is why QCARDS looks for them.) Thee
  240.  RIGHT$ function is then used trim away the extra byte,h
  241.  leaving a value that may correspond to one of the DIRECTION
  242.  keys. Use a SELECT CASE construction to respond to those key-
  243.  presses that represent numeric-keypad DIRECTION keys.
  244.  Adjust the cards according to the key pressed by the user,l
  245.  then call the ShowCards procedure to show adjusted stack.
  246.  This is the bottom of the unconditional DO loop.e
  247.  The execution sequence of the module-level code ends here.
  248.  The program may terminate elsewhere for legitimate reasons,
  249.  but the normal execution sequence ends here. Statements
  250.  beyond the END statement are executed only in response to
  251.  other statements.
  252.  This first label, MemoryErr, is an error handler.
  253. Not enough memory. Can't read file."
  254.  Data statements for screen output - initialized for 25 rows. Can be
  255.  modified for 43-row mode if you have an EGA or VGA adapter.
  256.   "                  
  257. J  "                  
  258.                                        
  259.   "               
  260.   "               
  261.                                        
  262. "! "            
  263. j! "            
  264.                                        
  265. ! "         
  266. ! "         
  267.                                        
  268. B" "      
  269. " "      
  270.                                        
  271. " "   
  272. # "   
  273.                                        
  274.  _____________________________________ 
  275.  Note: _______________________________ 
  276.                                        
  277.  Birth: __/__/__   Phone: ___-___-____ 
  278.                                        
  279.  Street: _____________________________ 
  280.                                        
  281.  City: ____________ ST: __  Zip: _____ 
  282.  Color codes and strings for view-mode help"
  283. & 0,  "Select card with:"
  284. && 1, "      UP"
  285. @& 1, "      DOWN"
  286. Z& 1, "      PGUP"
  287. t& 1, "      PGDN"
  288. & 1, "      HOME"
  289. & 1, "      END"
  290. & 1, ""
  291. ' 1, ""
  292.  Color codes and strings for edit-mode help"
  293.  ' 0,  "Next field:"
  294. 8' 1, "      TAB"
  295. T' 0,  "Accept card:"
  296. n' 1, "      ENTER"
  297. ' 0,  "Edit field:"
  298. ' 1, "      DEL     BKSP"
  299. ' 1, "      RIGHT   LEFT"
  300. ' 1, "      HOME    END"
  301. F( 1, "      INS     ESC"
  302.  Row, column, and length of each field
  303. ~( 14, 6, 37                      
  304.  Names
  305. ( 16, 12, 31                     
  306.  Notes
  307. ( 18, 13, 2                      
  308.  Month
  309. $) 18, 16, 2                      
  310. \) 18, 19, 2                      
  311.  Year
  312. ) 18, 31, 12                     
  313.  Phone
  314. ) 20, 14, 29                     
  315.  Street
  316. * 22, 12, 13                     
  317.  Citye
  318. >* 22, 29, 2                      
  319.  State
  320. t* 22, 38, 5                      
  321.  0, 0, 0
  322. AsciiKey
  323. * AsciiKey - Handles ASCII keys. You can add new commands by
  324. * assigning keys and actions here and adding them to the command
  325. * line displayed by the ShowCmdLine SUB. For example, you could adde
  326. * L (for Load new file) to prompt the user for a new database file.e
  327. * Params: UserChoice$ - key pressed by the usera
  328.      TopCard - the number of the current record
  329.      LastCard - the number of records
  330.  Edit the current card.
  331. Editing Card..."
  332.  Add and edit a blank or duplicate card.
  333.  Duplicate of top card
  334.  Initialize new card. 
  335. Editing Card..."
  336.  Move deleted card to end and adjust last card.d
  337.  Find a specified card.
  338. Enter fields for search (blank fields are ignored)
  339. Can't find card. Press any key..."
  340.  Sorts cards by a specified field.
  341. TAB to desired sort field, then press ENTER"
  342.  Prints address of top card on printer.E
  343.  Terminates the program.
  344. CleanUp
  345. * CleanUp - Writes all records from memory to a file. Deletedr
  346. * records (past the last card) will not be written. The valid records 
  347. * are written to a temporary file. The old file is deleted, and thed
  348. * new file is given the old name..
  349. * Params: LastCard - the number of valid records
  350. * Output: Valid records to "QCARDS.DAT" through TMPFILE$
  351.  Write records to temporary file in their current sort order.n
  352.  Delete old file and replace it with new version. 
  353. QCARDS.DAT
  354. QCARDS.DAT
  355. ClearHelp
  356. * ClearHelp - Writes spaces to the help area of the screen.r
  357. * Params: None
  358. * Output: Blanks to the screen
  359.  Clear key helps
  360.  Clear command line 
  361. DrawCards
  362. * DrawCards - Initializes screen by setting the color, setting the width
  363. * and height, clearing the screen, and hiding the cursor. Then writes card
  364. * text and view-mode help to the screen.
  365. * Params: None
  366. * Output: Text to the screen
  367.  Clear screen to current color.e
  368.  Display line characters that form cards.
  369.  Display help.
  370. EditCard
  371. * EditCard - Edits each field of a specified record.
  372. * Params: Card - the record to be edited
  373. * Return: Since Card is passed by reference, the edited version is
  374.      effectively returned.a
  375.  Set NextFlag and continue editing each field.
  376.  NextFlag is cleared when the user presses ENTER.e
  377.  Start with first field.
  378.  Edit string fields directly. 
  379.  Result of edit determines whether to continue.
  380.  Convert numeric fields to strings for editing.
  381.  Convert result back to number.
  382. InitIndex
  383. * InitIndex - Reads records from file and assigns each value to.
  384. * array records. Index values are set to the actual order of the
  385. * records in the file. The order of records in the array may changer
  386. * because of sorting or additions, but the CardNum field alwaysa
  387. * has the position in which the record actually occurs in the file.r
  388. * Params: LastCard - number of records in array 
  389. * Input:  File "QCARDS.DAT""
  390.  Read a record from the file and put each field in the array. 
  391. PrintLabel
  392. * PrintLabel - Prints the name, address, city, state, and zip code from
  393. * a card. This SUB could easily be modified to print a return addresso
  394. * or center the address on an envelope.f
  395. * Params: Card - all the data about a person
  396. * Output: Printera
  397. SortIndex
  398. * SortIndex - Sorts all records in memory according to a specified
  399. * field. After the sort, the first record in memory becomes the top
  400. * card. Note that although the order is changed in memory, the order
  401. * remains the same in the file. The true file order is shown by ther
  402. * CardNum field of each record. This SUB uses the Shell sort algorithm.e
  403. * Params: SortField - 0-based number of the field to sort on
  404.      LastCard - number of last card
  405.  Set comparison offset to half the number of records.s
  406.  Loop until offset gets to zero.
  407.  Assume no switches at this offset.n
  408.  Compare elements for the specified field and switch
  409.  any that are out of order.p
  410.  Sort on next pass only to location where last switch was made.g
  411.  No switches at last offset. Try an offset half as big.a
  412. ShowViewHelp
  413. * ShowViewHelp - Reads colors and strings for view-mode help and
  414. * puts them on screen.
  415. * Params: None
  416. * Output: Screen
  417.  Clear old help and display new.
  418.  Restore color and show command line.i
  419. ShowTopCard
  420. * ShowTopCard - Shows all the fields of the top card.d
  421. * Params: WorkCard - record to be displayed as top card
  422. * Output: Screen
  423.  Display each field of current card.
  424. ShowEditHelp
  425. * ShowEditHelp - Reads colors and strings for edit-mode help and
  426. * puts them on screen.
  427. * Params: None
  428. * Output: Screen
  429.  Clear old help and display new.
  430.  Restore normal color.
  431. ShowCmdLine
  432. * ShowCmdLine - Puts command line on screen with highlighted key
  433. * characters. Modify this SUB if you add additional commands.k
  434. * Params: None
  435. * Output: Screen
  436. dit Top   
  437. dd New   "
  438. opy to New   "
  439. elete   
  440. ind   
  441. ort   
  442. rint   "
  443. ShowCards
  444. * ShowCards - Shows all the fields of the top card and the top
  445. * field of the other visible cards.o
  446. * Params: TopCard - number of top card
  447.      LastCard - number of last card
  448. * Output: Screen
  449.  Show each field of top card. 
  450.  Show the Names field for other visible cards.
  451.  Show location and card number for next highest card.d
  452. EditString
  453. * EditString$ - Edits a specified string. This function 
  454. * implements a subset of editing functions used in the QuickBASICs
  455. * environment and in Windows. Common editing keys are recognized,s
  456. * including direction keys, DEL, BKSP, INS (for insert and overwrite
  457. * modes), ESC, and ENTER. TAB is recognized only if the NextFieldi
  458. * flag is set. CTRL-key equivalents are recognized for most keys.i
  459. * A null string can be specified if no initial value is desired.
  460. * You could modify this function to handle additional QB edite
  461. * commands, such as CTRL+A (word back) and CTRL+F (word forward).
  462. * Params: InString$ - The input string (can be null)
  463.      Length - Maximum length of string (the function beeps andr
  464.  refuses additional keys if the user tries to enter more)
  465.      NextField - Flag indicating on entry whether to accept TAB
  466.  key; on exit, indicates whether the user pressed TAB (TRUE)
  467.  or ENTER (FALSE)
  468. * Input:  Keyboard
  469. * Ouput:  Screen - Noncontrol keys are echoed.
  470.      Speaker - beep if key is invalid or string is too long
  471. * Return: The edited strings
  472.  Initialize variables and clear field to its maximum length.
  473.  Since Insert is STATIC, its value is maintained from onet
  474.  call to the next. Insert is 0 (FALSE) the first time thet
  475.  function is called.
  476.  Reverse video on entry.
  477.  Process keys until either TAB or ENTER is pressed.m
  478.  Get a key -- either a one-byte ASCII code or a two-byte
  479.  extended code.i
  480.  Translate two-byte extended codes to the one meaningful byte.
  481.  Translate extended codes to ASCII control codes.n
  482.  Handle HOME and END keys, since they don't have control
  483.  codes. Send NULL as a signal to ignore.
  484.  Make other key choices invalid.
  485.  Handle one-byte ASCII codes.i
  486.  If it is null, ignore it.
  487.  Accept field (and card if NextField is used).
  488.  Accept the field unless NextField is used. If NextField
  489.  is cleared, TAB is invalid.
  490.  Restore the original string.
  491.  CTRL+S or LEFT arrow moves cursor to left. 
  492.  CTRL+D or RIGHT arrow moves cursor to right.
  493.  CTRL+G or DEL deletes character under cursor.
  494.  CTRL+H or BKSP deletes character to left of cursor.
  495.  CTRL+V or INS toggles between insert and overwrite modes.
  496.  Echo ASCII characters to screen.s
  497.  Clear the field if this is first keystroke, thent
  498.  start from the beginning.
  499.  If insert mode and cursor not beyond end, insert character.
  500.  If overwrite mode and cursor at end (but not beyond),
  501.  insert character.
  502.  If overwrite mode and before end, overwrite character.
  503.  Consider other key choices invalid.
  504.  Print the modified string. 
  505.  Print the final string and assign it to function name.
  506. FindCard
  507. * FindCard - Finds a specified record. The user specifies as many
  508. * fields to search for as desired. The search begins at the card
  509. * after the current card and proceeds until the specified record or
  510. * the current card is reached. Specified records are retained between
  511. * calls to make repeat searching easier. This SUB could be enhancede
  512. * to find partial matches of string fields.i
  513. * Params: TopCard - number of top card
  514.      LastCard - number of last card
  515. * Params: None
  516. * Return: Number (zero-based) of the selected fieldo
  517.  Initialize string fields to null on the first call. (Note that thee
  518.  variables TmpCard and NotFirst, declared STATIC above, retain their
  519.  values between subsequent calls.)
  520.  Show top card, then use EditCardFunction to specify fieldsa
  521.  for search.
  522.  Search until a match is found or all cards have been checked.
  523.  Test name to see if it's a match.
  524.  Test note text.
  525.  Test month.
  526.  Test day.
  527.  Test year.
  528.  Test phone number.
  529.  Test street address.
  530.  Test city.
  531.  Test state.
  532.  Test zip code.
  533.  If match is found, set function value and quit, else next card.
  534.  Return FALSE when no match is found.e
  535. Prompt
  536. * Prompt$ - Prints a prompt at a specified location on the screen ando
  537. * (optionally) gets a user response. This function can take one of three
  538. * different actions depending on the length parameter.
  539. * Params: Msg$ - message or prompt (can be "" for no message)n
  540.      Row 
  541.      Column
  542.      Length - one of the following:
  543.  <1 - Don't wait for response
  544.  1 - Get character response
  545.  >1 - Get string response up to lengthe
  546. * Output: Keyboard
  547. * Output: Screen - noncontrol characters echoedo
  548. * Return: String entered by user
  549.  No return
  550.  Character return
  551.  String return
  552. SelectField
  553. * SelectField - Enables a user to select a field using TAB key.
  554. * TAB moves to the next field. ENTER selects the current field.
  555. * Params: None
  556. * Return: Number (zero-based) of the selected fieldr
  557.  Get first cursor position and set first FieldNum.
  558.  Rotate cursor through fields.
  559.  Set cursor on current field..
  560.  Get a TAB or ENTER.
  561.  If ENTER pressed, turn off cursor and return field.
  562.  Otherwise, it was TAB, so advance to next field.l
  563.